import * as r from '../base_rule'
const SensitiveItems = ['password', 'pwd'];
const meta = new r.QueryMeta({ name: '@security/dsl/sensitive-localstorage.ex' })
export default r.QvogDslRuleChain.create(meta)
  .when(x => x instanceof r.InvokeStmt) // 此处TypeGuard后，x被infer为InvokeExpr
  .when(x => x.expression.target === 'setItem' && x.expression.base instanceof r.Variable)

  .when(x => x.expression.argCount === 2 && x.expression.args[0] instanceof r.Constant)
  .select(x => x.expression.args[0])

  .when(x => x instanceof r.Constant)
  .when(x => SensitiveItems.includes(x.stringValue))

